package com.xja.shoppingmall.advice;

import com.xja.shoppingmall.vo.CommonResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author CHENCHEN
 * @title  全局异常捕获处理
 * @createTime 2021-12-1021:36
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = Exception.class)
    public CommonResponseVO handlerCommerceException(
            HttpServletRequest req, Exception ex
    ) {

        CommonResponseVO response = new CommonResponseVO(
                402, "Business processing exception"
        );
        response.setData(ex.getMessage());
        log.error("Shopping Mall Service Has Error: [{}]", ex.getMessage(), ex);
        return response;
    }
}
